home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / rexx / 1736 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: nntp.igs.net!usenet
  2. From: bnear@blvl.igs.net (Brian Near)
  3. Newsgroups: comp.lang.rexx
  4. Subject: Re: b tree search needed
  5. Date: Sun, 31 Mar 1996 21:01:02 -0500
  6. Organization: IGS - Information Gateway Services
  7. Distribution: world
  8. Message-ID: <ejzXxgabrEwS090yn@blvl.igs.net>
  9. References: <bgbxxgabrgbm090yn@blvl.igs.net> <4jj9nt$ssc@stratus.skypoint.net>
  10.  <4jk56j$23f2@usenetw1.news.prodigy.com>
  11. NNTP-Posting-Host: bnear.blvl.igs.net
  12.  
  13. In article <4jk56j$23f2@usenetw1.news.prodigy.com>,
  14. JXHQ58A@prodigy.com (Mark Lauritsen) wrote:
  15. >I don't know the details of the problem, but you can use stemmed 
  16. >variables to get REXX to do such a search for you.  I'll give you an 
  17. >example and hopefully you can adapt it to your situation.
  18. >
  19. >Suppose you have a list of "records" containing a key and some data.  For 
  20. >example, the key could be a person's name and the data could be 
  21. >address/phone/etc.  Now suppose the records are numbered 1 to N.  Given a 
  22. >name, you want to find the corresponding record (or its number).  
  23. >
  24. >number_from_key. = 0
  25. >
  26. >At this point, the value of number_from_key.anything is 0.  Now, code the 
  27. >following loop:
  28. >
  29. >do i = 1 to N   /* N is the total number of records. */
  30. >    temp = key.i
  31. >    number_from_key.temp = i  /* It's ok for temp to contain letters and 
  32. >blanks*/
  33. >end
  34. >
  35. >Now, given a key value, you can do something like this:
  36. >
  37. >rec_num = number_from_key.key_val /* Looks up rec num given key val. */
  38. >if rec_num = 0 say "No entry for" key_val
  39. >else                 say "Data for" key_val "is" data.rec_num
  40. >
  41. >I guarantee REXX can do the lookup internally much faster than you can by 
  42. >writting a binary search in REXX.  Internally, REXX is probably using a 
  43. >binary search, but it's written in C or some other compiled language.
  44. >
  45. >What do you think?
  46.  
  47. That's essentially what I was doing previously.  But while the search once
  48. the stem is loaded is admittedly fast, the wait to do this can be
  49. unacceptable.
  50. With the help from several folks here, I now have a way to determine the 
  51. size of the file (and the records it holds).  I now have a method to read
  52. records randomly, and I have a small, fast b-tree search.
  53. FWIW, the binary search is (IMHO), the preferred method.  A file of 500,000 
  54. records can be searched in approx 19 iterations max.
  55.  
  56.     -------------------------------
  57.            bnear@blvl.igs.net
  58.           casrsdfd@ibmmail.com
  59.     -------------------------------
  60.